package com.training.bt.entity;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@TableName("user_point")
public class UserPoint {
    @TableId(type = IdType.AUTO)
    private Long id;

    private Long userId;

    private Long uploadBytes;

    private Long downloadBytes;

    private int point;

    private LocalDateTime lastSeedingUpdate;

    public BigDecimal getRatio() {
        BigDecimal ratio = (downloadBytes == 0)
                ? new BigDecimal(uploadBytes)
                : new BigDecimal(uploadBytes).divide(new BigDecimal(downloadBytes), 2, RoundingMode.HALF_UP);

        return ratio;
    }
}
